package cn.lccabc.array.no0001;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: leet-code
 * @description:
 * @author: LiCC
 * @create: 2019-12-28 10:11
 */
public class Solution01 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int index = 0; index < nums.length; index++){
            int num = target - nums[index];
            if (map.get(num) != null){
                return new int[]{map.get(num), index};
            } else {
                map.put(nums[index], index);
            }
        }
        throw  new IllegalArgumentException();
    }

    public static void main(String[] args) {
        int[] nums = {2, 7, 11, 15};
        int target = 9;
        Solution01 solution = new Solution01();
        int[] a = solution.twoSum(nums, 9);
        System.out.println(a);
    }
}
